/**
 * 
 */
package nc.tb.querycdt;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

import nc.bs.logging.Logger;
import nc.tb.pub.util.NtbLogger;

/**
 * @author xuzx
 * 
 */
public class QryEditorTransferable implements Transferable {
	private static DataFlavor localObjectFlavor;

	private static DataFlavor[] supportedFlavors = { localObjectFlavor };

	private Object object = null;
	
	static {
		try {
			localObjectFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType);
		} catch (ClassNotFoundException cnfe) {
			NtbLogger.error(cnfe);
		}
	}

	public QryEditorTransferable(Object o) {
		object = o;
	}

	public Object getTransferData(DataFlavor df) throws UnsupportedFlavorException, IOException {
		if (isDataFlavorSupported(df)) {
			return object;
		}
		else {
			throw new UnsupportedFlavorException(df);
		}
	}

	public boolean isDataFlavorSupported(DataFlavor df) {
		return (df.equals(localObjectFlavor));
	}

	public static DataFlavor getTransferDataFlavor() {
		return localObjectFlavor;
	}

	public DataFlavor[] getTransferDataFlavors() {
		return supportedFlavors;
	}

}
